import store from '@/repo/store/store'
import {userActionsTypes} from "../repo/store/user";

//获取用户信息列表
const getUserMap = function (userIds) {
  return new Promise((resolve, reject) => {
    let userMap = store.getters.userMap
    let resolveIds = []
    for (let idx in userIds) {
      let userId = userIds[idx]
      if (userMap[userId] == null) {
        resolveIds.push(userId)
      }
    }
    if (resolveIds.length !== 0) {
      store.dispatch(userActionsTypes.FETCH_USER_MAP, resolveIds).then((val) => {
        let userData = {}
        for (let idx in userIds) {
          let userId = userIds[idx]
          userData[userId] = val[userId]
        }
        resolve(userData)
      }).catch((error) => {
        reject(error)
      })
    } else {
      let userData = {}
      for (let idx in userIds) {
        let userId = userIds[idx]
        userData[userId] = userMap[userId]
      }
      resolve(userData)
    }
  })
}
export default {

  getUserMap,
}
